package crack_sda2;

import math2.MathUtilities;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.Model;
import fem2.element.crack_sda2.SOSConstantJumpTetrahedraElement;
import fem2.material.FluencyCriteria;
import fem2.material.cohesive_law2.CohesiveLaw;
import fem2.material.cohesive_law2.IsotropicDamageCohesiveLaw;

public class Lshape3dMesh3_SOSConstantJumpTetrahedraElement_IsotropicDamageCohesiveLaw extends
		AbstractLshape3dUsingSDAElement {

	public Lshape3dMesh3_SOSConstantJumpTetrahedraElement_IsotropicDamageCohesiveLaw() {
		meshFileName = "mesh3-sos-isodamage.msh";
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		return new SOSConstantJumpTetrahedraElement(mp, mm, cl);
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		final double ft = 2.7;
		final double Gf = 0.065;

		FluencyCriteria softeningRule = new FluencyCriteria() {

			@Override
			public double computeFluencyValue(double v) {
				return ft * Math.exp(-v * ft / Gf);
			}

			@Override
			public double computeFluencyDerivative(double v) {
				double f = computeFluencyValue(v);
				return -(ft / Gf) * f;
			}
		};

		return new IsotropicDamageCohesiveLaw(Gf, ft, softeningRule);
	}

	public static void main(String[] args) {
		AbstractStructuralCrackDemo demo = new Lshape3dMesh3_SOSConstantJumpTetrahedraElement_IsotropicDamageCohesiveLaw();

		// double[] lambda = LinAlgUtilities.createLambdaArray(12.88, 0.1,
		// 13.0);
		// double[] lambda = LinAlgUtilities.createLambdaArray(12.88, 0.1,
		// 16.0); // not
		// // converged
		double[] lambda = MathUtilities.createLambdaArray(12.88, 0.1, 40.0);// bad
																			// but
																			// notable
																			// result

		demo.run(lambda);
	}
}
